﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace Business.Models
{
    public class DaiLy
    {
        [Key]
        [Required]
        public int IdDaiLy { get; set; }
        [Required]
        [Display(Description="Tên đại lý")] 
        public string TenDaiLy { get; set; }
        [Required]
        [DataType(DataType.Password)]
        public string MatKhau { get; set; }
        [Required]
        [DataType(DataType.EmailAddress)]
        public string Email { get; set; }
        [Required]
        public DateTime NgayTao { get; set; }
        public bool HoatDong { get; set; }
        [Required]
        public string SoDienThoai { get; set; }
        
        public int NguoiTao { get; set; }
        [ForeignKey("NguoiTao")]
        public virtual  Administrators administrator { get; set; }
    }

    public class DaiLyConfiguration : EntityTypeConfiguration<DaiLy>
    {

        public DaiLyConfiguration()
            : base()
        {

            HasKey(d => d.IdDaiLy);
            Property(d => d.IdDaiLy).
                HasColumnName("IdDaiLy").
                HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).
                IsRequired();
            Property(d => d.TenDaiLy).
                HasColumnName("TenDaiLy").
                IsRequired();
            Property(d => d.MatKhau).
                HasColumnName("MatKhau").
                IsRequired();
            Property(d => d.Email).
                HasColumnName("Email").
                IsRequired();
            Property(d => d.NgayTao).
                HasColumnName("NgayTao").
                IsRequired();
            Property(d => d.HoatDong).
                HasColumnName("HoatDong").
                IsRequired();
            Property(d => d.SoDienThoai).
                HasColumnName("SoDienThoai").
                IsRequired();
            ToTable("DaiLy","dbo");
        }

    }
}